<template>
  <div class="route-card" @click="handleClick">
    <div class="card-image">
      <a-image
        :src="route.routeCoverImage || defaultImage"
        :alt="route.routeName"
        :preview="false"
        fallback=""
      />
    </div>

    <div class="card-content">
      <h3 class="route-name" :title="route.routeName">{{ route.routeName }}</h3>

      <div class="tags">
        <a-tag v-for="tag in route.routeTags?.slice(0, 2)" :key="tag" size="small" color="green">
          {{ tag }}
        </a-tag>
      </div>

      <div class="route-details">
        <div class="detail-item" v-if="route.spendTime">
          <ClockCircleOutlined />
          <span>{{ route.spendTime }}</span>
        </div>
        <div class="detail-item" v-if="route.suitableTime">
          <CalendarOutlined />
          <span>{{ route.suitableTime }}</span>
        </div>
      </div>

      <div class="scenic-count" v-if="route.alongScenics?.length">
        <EnvironmentOutlined />
        包含 {{ route.alongScenics.length }} 个景点
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ClockCircleOutlined, CalendarOutlined, EnvironmentOutlined } from '@ant-design/icons-vue'

interface Props {
  route: API.RouteVO
}

interface Emits {
  (e: 'click', route: API.RouteVO): void
}

const props = defineProps<Props>()
const emit = defineEmits<Emits>()

const defaultImage = 'https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png'

// 处理点击事件
const handleClick = () => {
  emit('click', props.route)
}
</script>

<style scoped>
.route-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: all 0.3s ease;
  cursor: pointer;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.route-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.card-image {
  height: 180px;
  overflow: hidden;
}

.card-image :deep(.ant-image) {
  width: 100%;
  height: 100%;
}

.card-image :deep(.ant-image img) {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.route-card:hover .card-image :deep(.ant-image img) {
  transform: scale(1.05);
}

.card-content {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.route-name {
  font-size: 16px;
  font-weight: 600;
  color: #262626;
  margin: 0;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.route-details {
  display: flex;
  gap: 16px;
  margin: 8px 0;
}

.detail-item {
  display: flex;
  align-items: center;
  gap: 4px;
  color: #595959;
  font-size: 12px;
}

.scenic-count {
  color: #1890ff;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: auto;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .card-image {
    height: 160px;
  }

  .card-content {
    padding: 12px;
  }

  .route-name {
    font-size: 14px;
  }

  .route-details {
    flex-direction: column;
    gap: 4px;
  }
}
</style>
